package com.googlecode.animator.view.timeline
{
	import flash.events.MouseEvent;
	
	import mx.core.BitmapAsset;
	
	public class SplitMarkerEnd extends Marker
	{
		[Embed(source="com/googlecode/animator/assets/splitMarker.gif")]
		[Bindable]
		private var _splitMarkerImg:Class;
		
		private var _markerW:uint;
		
		public function SplitMarkerEnd(w:uint)
		{
			super(w);
			
			var icon:BitmapAsset = new _splitMarkerImg();
			
			_markerW = Math.round(w /3);
			icon.width = _markerW;
			icon.height = w;
			
			icon.x = w -_markerW;
			
			addChild(icon);
		}
		
		/**
		 * Responds to mouse move events anywhere. 
		 * @param evt
		 * 
		 */
		override protected function onMouseMoveAnywhere(evt:MouseEvent):void
		{
			
			if(_dragging && isDraggable)
			{
				y = offsetY;
				
				x = Math.round((container.mouseX - _objectOffset) / width) * width - parent.x;

				//Prevent less than 0		
				if(x < 0)
				{
					x = 0;
				}
				
				if(x != _lastPos)
				{
					dispatchEvent(new Event(OBJECT_MOVE, true));
				}
					
				_lastPos = this.x;
			} 
		}
		
		/**
		 * Provides a means of easily retrieving or setting the time this component represents. 
		 * @param t
		 * 
		 */
		override public function set time(t:Number):void
		{
			x = (width * t) - parent.x;
			//Prevent less than 0		
			if(x < 0)
			{
				x = 0;
			}
			
		}
		
		override public function get time():Number
		{
			return Math.round((x + parent.x) / width);
		}
	}
}